//
// Created by ls on 23-12-27.
//
#include <iostream>
#include <list>
#include <utility>
using namespace std;

class Person {
public:
    Person(string name, const int age, const double height):
        m_Name(std::move(name)),
        m_Age(age),
        m_Height(height) { }


    int m_Age;
    double m_Height;
    string m_Name;
private:

};


// 制定排序规则
bool comparePerson(Person &p1, Person &p2)
{
    // // 按照年龄做一个升序
    // if (p1.m_Age == p2.m_Age) {
    //     // 年龄相同
    //     return p1.m_Height > p2.m_Height;
    // }
    // return p1.m_Age < p2.m_Age;
    return p1.m_Age == p2.m_Age ? p1.m_Height > p2.m_Height : p1.m_Age < p2.m_Age;
}

void test01()
{
    list<Person> L;

    Person p1("刘备", 35 , 175);
    Person p2("孙权", 40 , 170);
    Person p3("曹操", 40 , 180);
    Person p4("赵云", 25 , 190);
    Person p5("张飞", 35 , 160);
    Person p6("关羽", 35 , 200);

    L.push_back(p1);
    L.push_back(p2);
    L.push_back(p3);
    L.push_back(p4);
    L.push_back(p5);
    L.push_back(p6);

    for (auto &it : L) {
        cout << "姓名： " << it.m_Name << " 年龄： " << it.m_Age
              << " 身高： " << it.m_Height << endl;
    }

    // 排序
    cout << "--------------------------------------" << endl;
    cout << "排序后" <<endl;

    L.sort(comparePerson);
    for (auto &it : L) {
        cout << "姓名： " << it.m_Name << " 年龄： " << it.m_Age
             << " 身高： " << it.m_Height << endl;
    }
}


int main()
{
    test01();
    return 0;
}